package work.mediway.bi.model.vo;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import work.mediway.bi.model.entity.InterfaceOper;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.List;

/**
 * @author bovane <bovane.ch@gmail.com>
 * @description
 * @create 2023-06-15 10:10
 */
@Data
@Slf4j
public class InterfaceOperVO {
    /**
     * 界面设置ID
     */
    private Integer id;

    /**
     * 界面名称
     */
    private String interfaceName;

    /**
     * 界面代码(存UUID)
     */
    private String interfaceCode;

    /**
     * 界面描述
     */
    private String interfaceDesc;


    /**
     * 创建人
     */
    private String createBy;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新人
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 启用状态
     */
    private Boolean actived;

    /**
     * 发布状态
     */
    private String pushStatus;

    /**
     * 数据配置
     */
    private String dataConfig;

    /**
     * 原生json
     */
    private JSON rawJson;

    public static List<InterfaceOperVO> convert(List<InterfaceOper> result) {
        List<InterfaceOperVO> interfaceOperVOS = CollUtil.newArrayList();
        for (InterfaceOper interfaceOper : result){
            InterfaceOperVO interfaceOperVO = new InterfaceOperVO();
            interfaceOperVO.setId(interfaceOper.getId());
            interfaceOperVO.setInterfaceCode(interfaceOper.getInterfaceCode());
            interfaceOperVO.setInterfaceName(interfaceOper.getInterfaceName());
            interfaceOperVO.setInterfaceDesc(interfaceOper.getInterfaceDesc());
            interfaceOperVO.setActived(interfaceOper.getActived());
            interfaceOperVO.setPushStatus(interfaceOper.getPushStatus());
            interfaceOperVO.setDataConfig(interfaceOperVO.getDataConfig());
            interfaceOperVO.setCreateBy(interfaceOper.getCreateBy());
            interfaceOperVO.setCreateTime(interfaceOper.getCreateTime());
            interfaceOperVO.setUpdateBy(interfaceOper.getUpdateBy());
            interfaceOperVO.setUpdateTime(interfaceOper.getUpdateTime());
            JSON json = JSON.parseObject(interfaceOper.getRawJson(), Feature.OrderedField);
            interfaceOperVO.setRawJson(json);
            interfaceOperVOS.add(interfaceOperVO);
        }
        return interfaceOperVOS;
    }
}
